package com.example.myblog_ssm.service;

import com.example.myblog_ssm.entity.ArticleInfo;
import com.example.myblog_ssm.entity.VO.UserInfoVO;
import com.example.myblog_ssm.mapper.ArticleMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22479
 * Date: 2023-03-21
 * Time: 9:57
 */
@Service
public class ArticleService {
    @Resource
    private ArticleMapper articleMapper;

    /**
     * 获取文章数量
     *
     * @param uid
     * @return
     */
    public UserInfoVO getArtCountByUid(Integer uid) {
        return articleMapper.getArtCountByUid(uid);
    }


    /**
     * 获取用户自己写的文章列表
     *
     * @param uid
     * @return
     */
    public List<ArticleInfo> getMyList(Integer uid) {
        return articleMapper.getMyList(uid);
    }

    /**
     * 删除文章
     *
     * @param id
     * @param uid
     * @return
     */
    public int del(Integer id, Integer uid) {
        return articleMapper.del(id, uid);
    }

    /**
     * 通过Id获取文章详情
     *
     * @param id
     * @return
     */
    public ArticleInfo getDetail(Integer id) {
        return articleMapper.getDetail(id);
    }


    /**
     * 阅读量自增
     *
     * @param id
     * @return
     */
    public int incrRCount(Integer id) {
        return articleMapper.incrRcount(id);
    }

    /**
     * 添加文章功能
     *
     * @param articleInfo
     * @return
     */
    public int add(ArticleInfo articleInfo) {
        return articleMapper.add(articleInfo);
    }

    /**
     * 修改发布过的文章
     *
     * @param articleInfo
     * @return
     */
    public int update(ArticleInfo articleInfo) {
        return articleMapper.update(articleInfo);
    }

    /**
     * 分页功能
     *
     * @param psize
     * @param offsize
     * @return
     */
    public List<ArticleInfo> getListByPage(Integer psize, Integer offsize) {
        return articleMapper.getListByPage(psize, offsize);
    }

    /**
     * 数据库中存储的文章总数
     *
     * @return
     */
    public int getCount() {
        return articleMapper.getCount();
    }

    /**
     * 定时发布博客功能
     *
     * @return
     */
    public int scheadd(ArticleInfo articleInfo) {
        return articleMapper.scheadd(articleInfo);
    }
}
